package l2

import (
	"zstackgo/pkg/header/message"
	"zstackgo/pkg/header/other"
)

var (
	_ other.APIAuditor = new(APICreateL2NetworkMsg)
)

/**
 * @api create l2Network
 * @category l2Network
 * @cli
 * @httpMsg {
 * "org.zstack.header.network.l2.APICreateL2NetworkMsg": {
 * "name": "TestL2Network",
 * "description": "Test",
 * "zoneUuid": "48c5febd96024e33809cc98035d79277",
 * "physicalInterface": "eth0",
 * "type": "L2NoVlanNetwork",
 * "session": {
 * "uuid": "d93f354c4339450e8c2a4c31de89da15"
 * }
 * }
 * }
 * @msg {
 * "org.zstack.header.network.l2.APICreateL2NetworkMsg": {
 * "name": "TestL2Network",
 * "description": "Test",
 * "zoneUuid": "48c5febd96024e33809cc98035d79277",
 * "physicalInterface": "eth0",
 * "type": "L2NoVlanNetwork",
 * "session": {
 * "uuid": "d93f354c4339450e8c2a4c31de89da15"
 * },
 * "timeout": 1800000,
 * "id": "7b58a8e291e54d41bc3fe643bb1c76b4",
 * "serviceId": "api.portal"
 * }
 * }
 * @result see :ref:`APICreateL2NetworkEvent`
 * @since 0.1.0
 */
type APICreateL2NetworkMsg struct {
	*message.APICreateMessage

	Name              string `validate:"required,max=255"`
	Description       string `validate:"max=2048"`
	ZoneUuid          string `validate:"required"`
	PhysicalInterface string `validate:"required,max=1024"`
	Type              string
	VSwitchType       string `validate:"max=1024,oneof=LinuxBridge OvsDpdk"`
}

func (am *APICreateL2NetworkMsg) Audit(msg message.APIMessage, rsp message.APIEvent) *other.Result {
	var id string
	if rsp.IsSuccess() {
		id = rsp.(*APICreateL2NetworkEvent).Inventory.Uuid
	}

	return other.NewResult(id, "L2NetworkVO")
}
